package com.bit.ThreadTest.newTest;

import java.util.concurrent.CountDownLatch;

public class TestCountDownLatch {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(8);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("起跑！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                countDownLatch.countDown();
                System.out.println("撞线！");
            }
        };
        for (int i = 0; i < 8; i++) {
            Thread thread = new Thread(runnable);
            thread.start();
        }
        countDownLatch.await();
        System.out.println("结束！");
    }
}
